class Solution
{
public:
    string lastSubstring(string s)
    {
        int n = s.size();
        int front = n - 2;
        int end = n - 1;
        while (front >= 0)
        {
            int i = 0;
            while (true)
            {
                if (front + i == end || end + i == n)
                {
                    end = front;
                    break;
                }
                if (s[front + i] > s[end + i])
                {
                    end = front;
                    break;
                }
                else if (s[front + i] < s[end + i])
                {
                    break;
                }
                ++i;
            }

            --front;
        }
        return s.substr(end);
    }
};